<!--
 * @Author: 李天惊 uf_lee@163.com
 * @Date: 2022-08-15 16:45:26
 * @LastEditors: 李小晴 2689279066@qq.com
 * @LastEditTime: 2023-10-25 09:17:28
 * @FilePath: \grazlink20\uc_sys\src\views\Asset\Pasture\components\See.vue
 * Copyright (c) 2022 by 李天惊 uf_lee@163.com, All Rights Reserved. 
-->
<script setup lang="ts">
import { PropType, reactive } from 'vue'
import { useTable } from '@/hooks/web/useTableTest'
import { Descriptions } from '@/components/Descriptions'
import { useCache } from '@/hooks/web/useCache'
import { spDieOrderDetailedListApi } from '@/api/sp/die'

const { wsCache } = useCache()
const dict: any = wsCache.get('dict')
const getDictLabel = (type, value) => {
  let data = dict[type].find((item) => {
    return item.value == value
  })
  return data ? data.label : ''
}

const props = defineProps({
  currentRow: {
    type: Object as PropType<Nullable<any>>,
    default: () => null
  },
  detailSchema: {
    type: Array as PropType<DescriptionsSchema[]>,
    default: () => []
  },
  id: {
    type: String,
    default: null
  }
})

const zcAssetSelectAdmin = async (val) => {
  val.die_order_id = props.currentRow.id
  return spDieOrderDetailedListApi(val)
}

const { register, tableObject, methods } = useTable<
  {
    total: number
    list: any[]
  },
  any
>({
  getListApi: zcAssetSelectAdmin,
  response: {
    data: 'data',
    count: 'count'
  }
})

const { getList } = methods

getList()

const d_columns = reactive<TableColumn[]>([
  {
    field: 'index',
    label: '序号',
    type: 'index',
    width: 30
  },
  {
    field: 'asset_code',
    label: '注射编码',
    width: 200
  },
  {
    field: 'asset_code_2',
    label: '项圈编码',
    width: 200
  },
  {
    field: 'earcon_code',
    width: 200,
    label: '耳标编码'
  },
  {
    field: 'asset_code_2',
    label: '项圈编号',
    width: 200
  },
  {
    field: 'breed',
    label: '畜别',
    formatter: (_: Recordable, __: TableColumn, cellValue: number | string) => {
      return getDictLabel('breed', cellValue)
    },
    width: 100,
    search: {
      show: true
    }
  },
  {
    field: 'breed_sub',
    label: '品种',
    width: 200,
    formatter: (_: Recordable, __: TableColumn, cellValue: number | string) => {
      return getDictLabel('breed_sub', cellValue)
    }
  },
  {
    field: 'loan_state',
    label: '贷款状态',
    width: 150,
    formatter: (_: Recordable, __: TableColumn, cellValue: number | string) => {
      return getDictLabel('loan_order_state', cellValue)
    }
  }
])
</script>

<template>
  <ContentWrap title="主数据">
    <Descriptions :schema="props.detailSchema" :data="props.currentRow">
      <template #type="{ row }: { row: any }">
        <div>{{ getDictLabel('die_type', row.type) }}</div>
      </template>
      <template #state="{ row }: { row: any }">
        <div>{{ getDictLabel('die_state', row.state) }}</div>
      </template>
    </Descriptions>
  </ContentWrap>

  <ContentWrap title="明细数据">
    <Table
      v-model:pageSize="tableObject.pageSize"
      v-model:currentPage="tableObject.currentPage"
      :columns="d_columns"
      :loading="tableObject.loading"
      :data="tableObject.tableList"
      :border="true"
      :pagination="{
        total: tableObject.count
      }"
      @register="register"
      :selection="false"
    />
  </ContentWrap>
</template>
